$(function() {
	$('#username').live('blur', function() {
		user.username2email();
	});
	$('#attr_L_id').change(function(){
		user.checkBrand();
	});
	$('#attr_M_id').change(function(){
		user.checkBrand();
	});
});



$(function() {
	var validator = $("#form1").validate({
		rules: {
			unique_id: "required",
			username: "required",
			c_username: "required",
			email:"required",
			department:"required",
			code:"required",
			entry_point:"required",
			status:"required"
		},
		messages: {
			unique_id: {
				required: "请输入工号！"
			},
			username: {
				required: "名称！"
			},
			c_username: {
				required: "中文姓名！"
			},
			email:{
				required: "请输入邮箱！"
			},
			department: {
				required: "请输入部门！"
			},
			code: {
				required: "请输入成本中心！"
			},
			entry_point: {
				required: "请输入入职时间！"
			},
			status: {
				required: "请选择状态！"
			}
		},
		errorPlacement: function(error, element) {
			if ( element.is(":radio") )
				error.appendTo( element.parent().next().next() );
			else if ( element.is(":checkbox") )
				error.appendTo ( element.next() );
			else
				error.appendTo( element.parent().next() );
		},
		submitHandler: function(form) {
			$("#form_submit").attr("disabled","disabled");
			form.submit();
		}
	});
});


var user = (function(){
 
	
	var  username2email = function() {
		$("#email").val($("#username").val());
	}
	


	
	var searchUser = function() {
		var kw = $('#kw').val();
		var url = _siteUrl+'admincp/hecUser/index/?kw='+kw;
		document.location.href = url;
	}
	
	 
	return {
		username2email : username2email,
		//updateLevel    :  updateLevel,
		//checkBrand     :  checkBrand,
		searchUser     :  searchUser
	};
 
})();